﻿using nplJobsCommon.JobSeeker;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using nplJobsBLL.ProcessSelectJobSeeker;
using nplJobsBLL.ProcessJobSeeker;
using nplJobsDAL.Common;
using Elmah;

public partial class JobSeekerMaster : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!Context.User.Identity.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
            }
            else
            {
                JobSeeker jobseeker = new JobSeeker();
                if (Session["jobseeker"] != null)
                {
                    jobseeker = (JobSeeker)Session["jobseeker"];
                }
                else
                {
                    ProcessSelectUserTypeByEmail selectUserType = new ProcessSelectUserTypeByEmail();
                    selectUserType.EMail = Context.User.Identity.Name;
                    selectUserType.invoke();
                    UserType userType = selectUserType.UserType;
                    if (userType.User == General.Users.JobSeeker.ToString())
                    {
                        Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
                        ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
                        jobSeeker.JobSeekerID = jobseekerID;
                        jobSeeker.invoke();
                        jobseeker = jobSeeker.JobSeeker.FirstOrDefault();
                        //Response.Redirect("/JobSeeker/EditProfile.aspx");
                    }
                    if (userType.User == General.Users.Employeer.ToString())
                    {
                        Response.Redirect("/Employeer/EmployeerEntry.aspx");
                    }
                }

                lblUser.Text = jobseeker != null ? jobseeker.FirstName + " " + jobseeker.LastName : string.Empty;
            }
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    public string Title { get; set; }

    protected void btnSignOut_Click(object sender, EventArgs e)
    {
        Session.Clear();
        Session.Abandon();
        Session.RemoveAll();
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
    }

    protected void lnkSignOut_OnClick(object sender, EventArgs e)
    {
        Session.Clear();
        Session.Abandon();
        Session.RemoveAll();
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();

    }

 
}
